package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.ItemComboBox;
import model.Model;
import controller.Controller;

public class ViewSoundSetting extends JPanel {
	private Model model;
	private Controller controller;
	private JComboBox comboboxSigned;
	private JComboBox comboBoxIndian;
	private JTextField inputSampleRate;
	private JTextField inputSampleSize;
	private JTextField inputChannel;

	public ViewSoundSetting(Controller controller, int x, int y, int width, int height) {
		this.model=controller.getModel();
		this.controller=controller;

		this.setBackground(Color.LIGHT_GRAY);
		this.setBounds(x,y,width,height);
		this.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 1));
		this.setVisible(false);
		refresh();}
	
	
	
	public void refresh() {
		//System.out.println("refreshSoundSetting");
		this.removeAll();
		JLabel labelSampleRate = new JLabel("SampleRate (Hz)");
		labelSampleRate.setPreferredSize(new Dimension(100, 20));
		this.add(labelSampleRate);
		inputSampleRate = new JTextField(String.valueOf(this.model.getSoundSetting().getSampleRate()));
		inputSampleRate.setPreferredSize(new Dimension(80, 20));
		
		this.add(inputSampleRate);
		
		JLabel labelSampleSize = new JLabel("Sample Size (bit)");
		labelSampleSize.setPreferredSize(new Dimension(100, 20));
		this.add(labelSampleSize);
		inputSampleSize = new JTextField(String.valueOf(this.model.getSoundSetting().getSampleSizeInBits()));
		inputSampleSize.setPreferredSize(new Dimension(80, 20));
		this.add(inputSampleSize);
		
		
		JLabel labelChannel = new JLabel("Channel");
		labelChannel.setPreferredSize(new Dimension(100, 20));
		this.add(labelChannel);
		inputChannel = new JTextField(String.valueOf(this.model.getSoundSetting().getChannels()));
		inputChannel.setPreferredSize(new Dimension(80, 20));
		this.add(inputChannel);
		
		
		//Signed : label + list déroulante true/false
		LabelSoundSetting labelSigned = new LabelSoundSetting("Signed");
		this.add(labelSigned);
		comboboxSigned = new JComboBox();
		comboboxSigned.setPreferredSize(new Dimension(80, 20));
		ItemComboBox first = new ItemComboBox("Big",true);
		ItemComboBox second = new ItemComboBox("Little",false);
		comboboxSigned.addItem(first);
		comboboxSigned.addItem(second);
		
		
		if(this.model.getSoundSetting().isSigned()) comboboxSigned.setSelectedIndex(0);
		else comboboxSigned.setSelectedIndex(1);
		this.add(comboboxSigned);
		
		
		//Big Indian : label + list déroulante true/false (false = little)
		LabelSoundSetting labelIndian = new LabelSoundSetting("Indian");
		this.add(labelIndian);
		comboBoxIndian = new JComboBox();
		comboBoxIndian.setPreferredSize(new Dimension(80, 20));
		ItemComboBox un = new ItemComboBox("Signed",true);
		ItemComboBox deux = new ItemComboBox("Not Signed",false);
		comboBoxIndian.addItem(un);
		comboBoxIndian.addItem(deux);
		
		if(this.model.getSoundSetting().isBigEndian()) comboBoxIndian.setSelectedIndex(0);
		else comboBoxIndian.setSelectedIndex(1);
		this.add(comboBoxIndian);
		
		
		this.setVisible(this.model.getShowSoundSetting() && this.model.getShowDialer());
		this.repaint();
		this.revalidate();
	}





	public JComboBox getComboboxSigned() {
		return comboboxSigned;
	}


	public JComboBox getComboBoxIndian() {
		return comboBoxIndian;
	}



	public JTextField getInputSampleRate() {
		return inputSampleRate;
	}



	public JTextField getInputSampleSize() {
		return inputSampleSize;
	}



	public JTextField getInputChannel() {
		return inputChannel;
	}
}


	
	class LabelSoundSetting extends JLabel{
		public LabelSoundSetting(String string){
			super(string);
			this.setPreferredSize(new Dimension(100, 20));
		}
	}
	
		
	
	

